#!/bin/bash

version="v0.0.2"

if [[ "$1" == "--deps" ]]
then
    if ! test -d .git
    then
	exit 0
    fi

    ref="$(cat .git/HEAD | cut -d' ' -f2)"
    if [[ "$?" != "0" ]]
    then
        exit 0
    fi

    if test -f ".git/$ref"
    then
        echo ".git/$ref"
    else
        echo ".git/refs/heads/master"
    fi
    exit 0
fi

if [[ "$1" == "--generate" ]]
then
    if test -d .git
    then
	gv=`git describe`
	if [[ "$?" == "0" ]]
	then
            if [[ "$(echo "$gv" | cut -d'-' -f1)" != "$version" ]]
            then
		echo "$0 has mismatched version" >&2
		exit 1
            fi

            version="${gv}-git"
	fi
    fi

    echo "#define PCONFIGURE_VERSION \"${version}\""
    
    exit 0
fi

exit 1
